<template>
  <div>
    <h3>新通知</h3>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="通知标题">
        <el-input v-model="form.AlertsTitle"></el-input>
      </el-form-item>
      <el-form-item label="通知内容">
        <el-input type="textarea" v-model="form.AlertsContent"></el-input>
      </el-form-item>
      <el-form-item label="学生可见">
        <el-switch v-model="form.StudentShow"></el-switch>
      </el-form-item>
      <el-form-item label="通知类型">
          <el-select v-model="form.NoticeId" placeholder="请选择通知类型">
            <el-option
              v-for="item in notice"
              :label="item.NoticeName"
              :value="item.NoticeId"
              :key="item.NoticeId"
            ></el-option>
          </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">提交申请</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      user:"",
      notice: "",
      form: {
        AlertsTitle: "",
        AlertsContent: "",
        StudentShow: false,
        NoticeId: '',
        WorkerId:"",
      }
    };
  },
  created() {
    this.getAllNotice();
  },
  mounted() {
    this.user = JSON.parse(sessionStorage("user"))
  },
  methods: {
    getAllNotice() {
      this.$axios({
        method: "get",
        url: this.$api.GetAllNotice
      }).then(res => {
        this.notice = res.data.message;
      });
    },
    onSubmit() {
      
      this.form.StudentShow = this.form.StudentShow?1:0
      this.form.WorkerId = this.user.WorkerId;
      console.log(JSON.stringify(this.form));
      this.$axios({
        method:"post",
        url:this.$api.InsertAlerts,
        headers: {
          "Content-Type": "application/json"
        },
        data: JSON.stringify(this.form)
      }).then((res)=>{
        console.log(res)
      })
    }
  }
};
</script>

<style scoped>
</style>
